

function addRow() {
    let table = document.getElementById('table');
    // console.log(table);
    var length = table.rows.length;
    // console.log(length);
    var newRow = table.insertRow(length);
    
    var nameCol = newRow.insertCell(0);
    var phoneCol = newRow.insertCell(1);
    var actCol = newRow.insertCell(2);

    nameCol.innerHTML = '未命名'
    phoneCol.innerHTML = '未命名'
    actCol.innerHTML = '<button onclick="editRow(this)">编辑</button> \
                <button onclick="deleteRow(this)">删除</button>'

    console.log(newRow);
}

function deleteRow(button) {
    var row = button. parentNode.parentNode;
    console.log(row);
    row.parentNode.removeChild(row);
}

function editRow(button) {
    console.log(button);
    // 行节点
    var row = button. parentNode.parentNode;
    var name = row.cells[0];
    var phone = row.cells[1];

    // 浏览器弹窗
    var inputName = prompt("请输入名字");
    var inputPhone = prompt("请输入联系方式");

    name.innerHTML = inputName;
    phone.innerHTML = inputPhone;
}